import { _get, _post, _delete } from "../../utils/request";
import util from "../../utils/util";
const app = getApp();

Page({
    data: {
        edit_if: false,
        items: [
            // {
            //     title: "模板1",
            //     description: "这是模板1",
            // },

        ],
        isshow_input: false,
        mb_name: ''
    },

    showPrompt() {
        this.setData({
            isshow_input: true
        })
    },
    showPrompt1() {
        this.setData({
            isshow_input: false
        })
    },
    bindKeyInput(e) {
        // console.log(e);
        this.setData({
            mb_name: e.detail.value
        })
    },
    //新增检测项
    async add() {
        let itemDto = {
            userId: app.userId,
            itemName: this.data.mb_name,
            vbizId: app.confirmId
        }
        await _post(`/item/editorItem`, itemDto).then(res => {
            console.log('编辑检测项成功');
        })
        this.getMb()
        this.setData({
            // items: this.data.items.concat(params),
            isshow_input: false
        })
    },
    //删除模板
    //开启编辑模式
    edit() {
        this.setData({
            edit_if: !this.data.edit_if
        })
    },
    delete(e) {
        console.log('del', e);
        let params = {
            sampleitemId: e.currentTarget.id,
            vbizId: app.confirmId
        }
        console.log('params', params);
        _get(`/item/deleteItem`, params).then(res => { console.log('删除成功', res); })
        this.getMb()
    },

    //模板列表接口
    getMb() {

        const params = {
            id: app.confirmId ? app.confirmId : app.test_id,
            userId: app.userId
        }
        _get(`/item/selectItem`, params).then(res => {
            console.log('mb', res.data['数据']);
            this.setData({
                items: res.data['数据'],
                title: res.data.title
            })

        })
    },
    //跳转到choose_mb1
    jump_mb1(e) {
        console.log('模板', e);
        app.jcx_id = e.currentTarget.id
        dd.navigateTo({
            url: '/pages/choose_mb1/choose_mb1'
        })
    },
    jump_home() {
        dd.reLaunch({
            url: '/pages/mytest/test_list/test_list'
        })
    },
    onLoad() {
        dd.setNavigationBar({
            title: '选择模板',
            backgroundColor: '#142e4f',
            success() {},
            fail() {},
        });
    },
    onReady() {
        this.getMb()
    },
});